(function(window, undefined){
  'use strict';
  var ns = window.beneath = window.beneath || {};

  function ParticleText(game, x, y, text, float){
    float = float || false;

    var ground = y;
    var dy = -(2 + 2 * Math.random());
    var dx = Math.random();

    var size = 3;
    if(float) {
      size = 5;
      dx *= 0.1;
      dy *= 0.1;
    }

    this.spr = game.add.bitmapText(x, y, 'font', text, size);
    if(float) {
      this.spr.align = 'center';
    }
    this.spr.entity = this;
    this.time = 1.0;

    this.update = function () {
      dx *= 0.99;
      dy *= 0.99;

      if(!float){
        dy += 0.075;
        this.time *= 0.95;


      } else {
        this.time *= 0.99;
      }
      
      this.spr.x += dx;
      this.spr.y += dy;

      this.spr.alpha = this.time;
      if(this.time < 0.01) {
        this.spr.destroy();
      }

    };
  }

  ns.ParticleText = ParticleText;
})(window);